// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import store from './store'
import config from 'config/config'
import Storage from './utils/storage'
//生成游客id
import { visit } from 'utils/Cache'
// import { bindDistri } from 'api/extensionApi'

visit.setCookieId()
import {
    NavBar,
    Toast,
    Swipe,
    SwipeItem,
    List,
    Rate,
    Tab,
    Tabs,
    DatetimePicker,
    Popup,
    Dialog,
    Picker,
    SwipeCell,
    CellGroup,
    PullRefresh,
    ImagePreview,
    ActionSheet,
    Area,
    Overlay,
    Switch,
    Uploader,
    Divider,
    Icon,
    RadioGroup,
    Radio,
    Button,
    Checkbox,
    Cell,
    CheckboxGroup,
    Step,
    Steps,
    NumberKeyboard,
    Field,
    Form,
    Search,
    NoticeBar,
    Loading,
    Skeleton,
    Calendar
} from 'vant'
import VConsole from 'vconsole'
import VueWechatTitle from 'vue-wechat-title'
// import VueScroller from 'vue-scroller'
import VueClipboard from 'vue-clipboard2' //剪切
import 'babel-polyfill' //这个是将es6转换成es5，解决安卓6.0及以下版本空白的问题
import Es6Promise from 'es6-promise' //这个是将es6转换成es5，解决安卓6.0及以下版本空白的问题
import waterfall from 'vue-waterfall2'  //瀑布流插件
require('es6-promise').polyfill() //这个是将es6转换成es5，解决安卓6.0及以下版本空白的问题
Es6Promise.polyfill() //这个是将es6转换成es5，解决安卓6.0及以下版本空白的问题



Vue.use(VueWechatTitle)
// Vue.use(VueScroller )
Vue.use(VueClipboard)
Vue.use(Swipe)
    .use(SwipeItem)
    .use(List)
    .use(Rate)
    .use(NavBar)
    .use(Toast)
    .use(Tab)
    .use(Tabs)
    .use(DatetimePicker)
    .use(Popup)
    .use(Dialog)
    .use(Picker)
    .use(SwipeCell)
    .use(CellGroup)
    .use(PullRefresh)
    .use(ImagePreview)
    .use(ActionSheet)
    .use(Area)
    .use(Overlay)
    .use(Switch)
    .use(Uploader)
    .use(Divider)
    .use(Icon)
    .use(Radio)
    .use(Cell)
    .use(Button)
    .use(CheckboxGroup)
    .use(Checkbox)
    .use(Step)
    .use(Steps)
    .use(RadioGroup)
    .use(NumberKeyboard)
    .use(Field)
    .use(Form)
    .use(Search)
    .use(NoticeBar)
    .use(Loading)
    .use(Skeleton)
    .use(waterfall)
	.use(Calendar)
	
// import lodash from 'lodash'
// Vue.prototype.lodash = lodash;

import '../public/js/mui.js'
// 初始化rem
import '../public/js/self-adaption.js'
// 初始化样式
import './assets/css/variable.css'
import './assets/css/common.css'
import './assets/css/ls-main.css'
// 样式引入
import './assets/css/style/index-style.css'
/* 列表样式 */
import './assets/css/style/list-style.css'
/* 导航 */
import './assets/css/style/m-tabs-style.css'
/* 结尾button */
import './assets/css/style/b-btn.css'
import './assets/css/style/popup-style.css'

// 引入iconfont
import './assets/iconfont/iconfont.js'
import './assets/iconfont/iconfont.css'

//引入这个懒加载插件
import VueLazyload from 'vue-lazyload'
Vue.use(VueLazyload, {
    error: require('./assets/images/default-goods-img.jpg'),
    loading: require('./assets/images/default-goods-img.jpg')
})

require('promise.prototype.finally').shim()

/*
  时间处理
    使用方法： {{ 1550022061000 | dateformat('YYYY:MM:DD')}}   dateformat   --里面日期格式随便改
*/
import moment from 'moment'
Vue.filter('dateformat', function (dataStr, pattern = 'YYYY-MM-DD HH:mm:ss') {
    return moment(dataStr).format(pattern)
})

Vue.prototype.$dateformat = function (dataStr, pattern = 'YYYY-MM-DD HH:mm:ss') {
    return moment(dataStr).format(pattern)
}
Vue.prototype.$inputMoney = `if(this.value=='00'){this.value='0';}else{this.value=this.value.replace(/[^\0-9.]/g, '').replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3')}` // 只能输入整数+小数，用法：<el-input :oninput="$inputMoney" />

Vue.filter('strEndFour', function (dataStr) {
    dataStr = dataStr || ''

    return dataStr.replace(/\s/g, '').replace(/(\d{4})\d+(\d{4})$/, '$2')
})

import drectives from '@/utils/drectives'
Vue.use(drectives)

//300ms延迟处理,IOS11以下才用上
import FastClick from 'fastclick'
const device = navigator.userAgent.toLowerCase().match(/cpu iphone os (.*?) like mac os/)
if (!device || parseInt(device[1]) < 11) {
    FastClick.attach(document.body)
}

Vue.prototype.$imgUrlHead = config.photoServer
Vue.prototype.$staticServer = config.staticServer
import utils from '@/utils/utils.js';Vue.prototype.$utils = utils// 各种实用的方法
import stringUtils from '@/utils/stringUtils.js';Vue.prototype.$stringUtils = stringUtils// 统一处理string字符串的方法
import checkInfo from '@/utils/checkInfo.js';Vue.prototype.$checkInfo = checkInfo;// 数据效验
import weChat from '@/utils/weChat';Vue.prototype.$weChat = weChat; // 引入微信JDK,config
import configfix from '@/config/configfix';Vue.prototype.$configfix = configfix; // config常量配置

import { getUrlKey } from 'utils/utils'

//mian.js不写调取接口逻辑，已搬到App.vue文件中
// let invitCode = getUrlKey('invitCode')
// if (invitCode) {
//     localStorage.setItem('invitCode', invitCode)
//     bindDistri({ invitationCode: invitCode }).then((res) => {})
// }

// 路由跳转
function toPage(name, query) {
    if (name.indexOf('/') > -1) {
        router.push({ path: name, query })
    } else {
        router.push({ name, query })
    }
}

function replaceToPage(name, query) {
    if (name.indexOf('/') > -1) {
        router.replace({ path: name, query })
    } else {
        router.replace({ name, query })
    }
}
Vue.prototype.$toPage = toPage
Vue.prototype.$replaceToPage = replaceToPage

Vue.config.productionTip = false

const storage = new Storage()
if (storage.get(config.StorageVconsole)) {
    let vConsole = new VConsole()
}

Vue.prototype.$EventBus = new Vue()

/* eslint-disable no-new */
new Vue({
    router,
    store,
    render: (h) => h(App)
}).$mount('#app')
